class Stack {
  constructor() {
    //栈中的元素
    this.items = [];
  }
  //栈常用方法
  //入栈
  push(el) {
    this.items.push(el);
  }
  //出栈
  pop() {
    return this.items.pop();
  }
  //查看栈顶元素
  peek() {
    return this.items[this.size() - 1];
  }
  //栈的长度
  size() {
    return this.items.length;
  }
  //判断栈的元素是否为空
  isEmpty() {
    return this.size() === 0;
  }
  //查看栈中所有元素
  toString() {
    return this.items.reduce((acc, curr) => (acc += curr + " "), "");
  }
}

//10进制转2进制  (除二取余反拼)

function dec2bin(decNumber) {
  const stack = new Stack();
  while (decNumber > 0) {
    stack.push(decNumber % 2);
    decNumber = Math.floor(decNumber / 2);
  }
  let binaryString = "";
  //依次出栈
  while (!stack.isEmpty()) {
    binaryString += stack.pop();
  }
  return binaryString;
}

console.log(dec2bin(100000));


//中缀表达式转后缀表达式
//中缀表达式:
//后缀表达式:
